//========================================================================
// FILENAME : adc.h
// CREATED : 23-02-2009
// AUTHOR : Jesper Aagaard Vuholm
// DESCR. : This file contains data used for our AD-conversions.
//
//------------------------------------------------------------------------
//
// REV. DATE/AUTHOR CHANGE DESCRIPTION
// 1.00 24-02-2009/Jesper basic prototype declarations added.
// 1.01 27-02-2009/Jesper prioritized channel selector for the ADMUX added.
//                        see the notes for: priority_list[PRIORITY_LIST_SIZE]
//========================================================================
#include <avr/io.h>

// ADC Setup
#define ADC_CHANNELS 6
#define PRIORITY_LIST_SIZE 255

// Variables used in AD-conversion
unsigned int ADC_raw_values[ADC_CHANNELS];

//=============================================================
// DESCR. : Hard-coded priority list, gives simple and very
// fast decision making. Used for setting up the ADMUX register.
//
// Usage. : Setup the table below until you have the "visit freq."
// for every pin as you want. Once setup, all you need to do is
// to increment the pointer(for this table), this will decide what
// channel the next ADC-conversion will come from.
//
// Size. : As for now the list will have 255 entries, that mean
// 1 entry will equal a AD conversion from that channel 0.392%
// of the time. If we want a higher resolution, we can just
// change the list size, to fit our needs.
//
// Channel to physical setup:
// *Channel*           *Physical*
//  0				    Gyroscope.
//  1					Accelerometer.
//  2                   Joystick.
//  3					AMP-meter right motor.
//  4                   AMP-meter left motor.
//  5                   Battery voltage.
// 	6					Not in use.
//  7                   Not in use.
//=============================================================
static const unsigned char priority_list[PRIORITY_LIST_SIZE] =
{		//0-99
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,2, //Joystick
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		//100-199
		0,1,0,1,0,1,0,1,0,3, //AMP-meter right motor.
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,4, //AMP-meter left motor.
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		//200-254
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,5, //Battery-voltage
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0,1,0,1,0,1,
		0,1,0,1,0
};

void ADC_init();
void ADC_setPin (unsigned char pin);
void ADC_start();
void ADC_startScan();
void ADC_stop();
